package com.unionpay.tool;

public class Version {

	public static int compare(String leftVersion, String rightVersion) {
		String[] arrleft = leftVersion.split("\\.");
		String[] arrRight = rightVersion.split("\\.");
		int idx = 0;
		int minLength = Math.min(arrleft.length, arrRight.length);// 取最小长度值
		int diff = 0;
		while (idx < minLength //
				&& (diff = arrleft[idx].length() - arrRight[idx].length()) == 0 // 先比较长度
				&& (diff = arrleft[idx].compareTo(arrRight[idx])) == 0) { // 再比较字符
			++idx;
		}
		// 如果已经分出大小，则直接返回，如果未分出大小，则再比较位数，有子版本的为大；
		diff = (diff != 0) ? diff : arrleft.length - arrRight.length;
		return diff;
	}
}
